/*
 * @ProjectName: 编程学习
 * @Copyright:   2019 HangZhou Yi Dev, Ltd. All Right Reserved.
 * @address:     http://Yi.tech
 * @date:        2019/5/7 22:25
 * @email:       xiazhaoyang@live.com
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package com.example.auth.rest;

import com.example.auth.common.base.ResponseJson;
import com.example.auth.dao.common.model.UserInfo;
import com.example.auth.service.IUserDetailsService;
import org.apache.tomcat.util.http.fileupload.RequestContext;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.Principal;

/**
 * <p>
 *
 * </p>
 *
 * @author Yi
 * @version v1.0.0
 * @date 2019/5/7 22:25
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人} 2019/5/7
 * @modify reason: {方法名}:{原因}
 * ...
 */
@RestController
public class UserController {

    @Resource(name = "userDetailsService")
    private IUserDetailsService userDetailsService;

    @RequestMapping("/user/me")
    public Principal user(Principal principal) {
        System.out.println(principal);
        return principal;
    }

    @PostMapping("/user/register")
    public ResponseJson register(@RequestBody UserInfo userInfo){
        userDetailsService.register(userInfo);
        return ResponseJson.builder().code("0").msg(String.format("%s,恭喜您注册成功！",userInfo.getUserName())).build();
    }
}